﻿Option Strict On
Option Explicit On

Partial Class private_secure_members_pages_default2
    Inherits System.Web.UI.Page

    Dim u As MembershipUser
    Dim personId As Int32
    Dim entityid As Integer

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        u = Membership.GetUser(HttpContext.Current.User.Identity.Name)

        Dim getpersonid As New GetPersonIdFromUserId()

        Try
            personId = getpersonid.GetPersonId(CType(u.ProviderUserKey, Guid))
            Dim entityidTA As New LogginsLogDSTableAdapters.usp_GetEntityListFull_ByPersonIdTableAdapter()
            Dim entityidDT As LogginsLogDS.usp_GetEntityListFull_ByPersonIdDataTable
            entityidDT = entityidTA.GetData(personId)
            Me.ddlEntity.DataBind()
        Catch ex As Exception
            Throw ex
        End Try

        Dim strDisplayName As String = ""
        Dim strUserPlan As String = ""

        Me.lblUserDisplay.Text = strDisplayName + " " + strUserPlan

        Dim spTA As New LogginsLogDSTableAdapters.usp_dashboard_overviewTableAdapter()
        Dim spDT As New LogginsLogDS.usp_dashboard_overviewDataTable

        If CDbl(ddlEntity.SelectedValue) > 0 Then

            spDT = spTA.GetData(CType(personId, Integer), CType(ddlEntity.SelectedValue, Integer?))

            For Each spDTRow As LogginsLogDS.usp_dashboard_overviewRow In spDT

                'Entity
                Me.lblEntityCount.Text = CStr(spDTRow.EntityCount)

                ' Associates
                Me.lblAssociateRequests.Text = CStr(spDTRow.AssociateRequestsMade)
                Me.lblAssociatesCount.Text = CStr(spDTRow.AssociateCount)
                Me.lblAssociatesNotUsed.Text = CStr(spDTRow.AssociatesNotYetLoggedIn)
                Me.lblAssociatesActive.Text = CStr(spDTRow.AssociatesActive)

                'Campaign
                Me.lblCampaignCount.Text = CStr(spDTRow.CampaignCount)
                Me.lblCampaignFilterCount.Text = CStr(spDTRow.CampaignFilterCount)

                'Credits
                Me.lblCreditsRemaining.Text = CStr(spDTRow.CreditsRemaining)
                Me.lblCreditsPurchased.Text = CStr(spDTRow.CreditsUsed)
                Me.lblCreditsUsed.Text = CStr(spDTRow.CreditsPurchased)

                'Lists & Recipients
                Me.lblListsCount.Text = CStr(spDTRow.PersonListCount)
                Me.lblRecipientsCount.Text = CStr(spDTRow.RecipientsCount)

                'Single Use Tokens
                Me.lblSingleUseCount.Text = CStr(spDTRow.SingleTokenLoginsCount)
                Me.lblSingleUseUsed.Text = CStr(spDTRow.SingleTokenLoginsUsed)

            Next
        End If
    End Sub
    Protected Sub SqlEntity_ds_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlEntity_ds.Selecting
        e.Command.Parameters("@PersonId").Value = CType(personId, Integer)
    End Sub
End Class
